package com.ywps.vaas.framework.util

import com.alibaba.fastjson.JSONObject
import org.apache.spark.sql.Row

object JsonUtil {

  /**
   * 获取json对象所有的key值
   * @param json
   */
  def getKeysFromJsonObject(json: JSONObject): List[String] = {
    var list =List[String]()
    json.entrySet.asScala.foreach(entry => list = list:+entry.getKey)
    list
  }

  /**
   * 获取json对象所有的key值
   * @param json
   */
  def getValuesFromJsonObject(json: JSONObject): Row = {
    var list =List[String]()
    json.entrySet.asScala.foreach(entry => list = list:+entry.getValue.toString)
    val row: Row = Row.fromSeq(list)
    row
  }

  /**
   * 获取json对象所有的key值
   * @param json
   */
  def getListValuesFromJsonObject(json: JSONObject): List[String] = {
    var list =List[String]()
    json.entrySet.asScala.foreach(entry => list = list:+entry.getValue.toString)
    list
  }
}
